from quart import Quart, jsonify
import uuid
import json

# Vercel serverless函数入口点
async def app(scope, receive, send):
    """ASGI应用入口点"""
    if scope['type'] == 'http':
        # 生成请求ID
        request_id = str(uuid.uuid4())
        
        # 健康检查响应
        response_data = {
            'code': 200,
            'data': {
                'service': '服务健康',
                'status': 'ok'
            },
            'message': '服务运行正常',
            'requestId': request_id
        }
        
        # 构建HTTP响应
        response_body = json.dumps(response_data, ensure_ascii=False).encode('utf-8')
        
        await send({
            'type': 'http.response.start',
            'status': 200,
            'headers': [
                [b'content-type', b'application/json'],
                [b'x-request-id', request_id.encode('utf-8')],
                [b'content-length', str(len(response_body)).encode('utf-8')]
            ]
        })
        
        await send({
            'type': 'http.response.body',
            'body': response_body
        })
    else:
        # 不支持的协议类型
        await send({
            'type': 'http.response.start',
            'status': 404,
            'headers': [[b'content-type', b'text/plain']]
        })
        
        await send({
            'type': 'http.response.body',
            'body': b'Not Found'
        })